﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;
using QLBH.Models;

namespace QLBH.Modules
{
    public partial class ucOrders : UserControl
    {
        private OrdersController ObjController;
        public ucOrders()
        {
            InitializeComponent();
            ObjController = new OrdersController(this);
        }
        public void DisplayData(List<OrdersModel> model)
        {
            dataGridViewOrder.DataSource = model;
        }

        private void ucOrders_Load(object sender, EventArgs e)
        {
           this.dataGridViewOrder.AutoGenerateColumns = false;
            ObjController.LoadData();
            if (dataGridViewOrder.SelectedRows.Count <= 0)
            {
                btnDelete.Enabled = false;
                btnEdit.Enabled = false;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            ObjController.Add();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            ObjController.Edit();
        }

        public OrdersModel SelectItem()
        {
            if (dataGridViewOrder.SelectedRows.Count > 0)
            {
                return dataGridViewOrder.SelectedRows[0].DataBoundItem as OrdersModel;
            }
            else
            {
                return null;
            }
        }
    }
}
